package com.shop.shop_end.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;
import java.util.Map;

@Component
public class CommonUtil {
    /* 日志 */
    final Logger logger = LoggerFactory.getLogger(CommonUtil.class);

    /* 获取基本环境 */
    public Map<String, String[]> getParameters() {// 封装为Map的requestParameters
        ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        return attrs.getRequest().getParameterMap();
    }

    public HttpServletRequest getRequest() {
        ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        return attrs.getRequest();
    }

    public HttpSession getSession() {
        HttpSession session = null;
        session = this.getRequest().getSession();
        return session;
    }
}
